package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.enTableModel;


/**
 * Created by qi.wang on 2017/3/16.
 */

public class EnTableAdapter extends BaseAdapter{
    public List<enTableModel.ListBean> list=new ArrayList<>();
    Context context;
    LayoutInflater inflater;
    public int flag=-1;
    public EnTableAdapter(Context context, List<enTableModel.ListBean> data){
        this.context=context;
        this.list=data;
        inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            holder=new ViewHolder();
            convertView=inflater.inflate(R.layout.list_item_enshop,parent,false);
            holder.users_name=(TextView)convertView.findViewById(R.id.good_evaluate);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        holder.users_name.setTag(position);
        enTableModel.ListBean newsModel=list.get(position);
        if(newsModel.getKeycode().equals("-1")){
            holder.users_name.setText(newsModel.getName());
        }else {
            holder.users_name.setText(newsModel.getName() + " " + newsModel.getNum());
        }
        if(flag==position){
            holder.users_name.setBackgroundResource(R.drawable.btn_backroud);
            holder.users_name.setTextColor(Color.parseColor("#ffffff"));
        }else{
            holder.users_name.setBackgroundResource(R.drawable.btn_gray_corn);
            holder.users_name.setTextColor(Color.parseColor("#777777"));
        }
        return convertView;
    }

    public static class ViewHolder{
        TextView users_name;
    }
}
